<template>
  <div id="InformationBase">
    <div class="like-head">
      <div style="display: flex; margin-top: 20px">
        <div style="margin-right: 30px">
          <img class="imgs" :src="headerData.logoUrl" alt="" />
        </div>
        <div class="right-head">
          <div style="display: flex">
            <div class="collegeName" style="margin-right: 50px">
              {{ headerData.cnName || headerData.collegeName }}
            </div>
            <div class="curr" @click="handleMyLike" v-if="studentId">
              <span
                class="iconfont"
                :class="isSelected ? 'icon-aixin1' : 'icon-aixin'"
              ></span>
              {{ isSelected ? '已关注' : '关注' }}
            </div>
          </div>
          <div class="tags">
            <el-tag
              type="info"
              size="small"
              style="margin-right: 3px"
              v-for="item in headerData.features"
              :key="item"
            >
              {{ item }}</el-tag
            >
          </div>
          <div class="colldec">
            {{ headerData.provinceName }}/ {{ headerData.cityName }} /
            {{ headerData.categor }} {{ headerData.belong }}
          </div>
        </div>
      </div>
    </div>

    <div class="tabs">
      <el-tabs
        v-model="activeName"
        class="demo-tabs"
        @tab-click="handleClick"
        v-infinite-scroll="load"
      >
        <el-tab-pane label="基本介绍" name="first">
          <div v-if="!isDecAllShow">
            <div style="display: flex">
              <div style="background: #fafafa; padding: 20px 10px">
                <div
                  style="
                    display: flex;
                    text-align: center;
                    justify-content: space-between;
                    border-bottom: 1px dashed #e5e6eb;
                    padding-bottom: 8px;
                  "
                >
                  <div
                    v-for="(item, key, index) in jibenInfo"
                    :key="index"
                    style="margin: 0 10px"
                  >
                    <img
                      :src="jbIconModul[key]"
                      style="margin: 0 24rpx; width: 50px; height: 50px"
                    />
                    <div
                      style="
                        font-size: 12px;
                        margin-top: 10px;
                        text-align: center;
                      "
                    >
                      {{ item }}
                    </div>
                  </div>
                </div>
                <div>
                  <div class="introduction">
                    {{ headerData.introduction_simple }}
                    <span class="allBtn curr" @click="handleLookAll"
                      >查看全部</span
                    >
                  </div>
                </div>
              </div>
              <div
                style="
                  display: flex;
                  justify-content: space-evenly;
                  background: #fafafa;
                  width: 1000px;
                  margin-left: 20px;
                "
              >
                <div
                  class="ranking-item"
                  v-for="(item, index) in rankingInfo"
                  :key="index"
                  style="text-align: center"
                >
                  <div class="text-ranking-value">{{ item }}</div>
                  <div class="text-ranking-title">{{ index }}</div>
                </div>
              </div>
            </div>

            <!-- 特色专业 -->
            <div>
              <!-- 特色专业 -->
              <div>
                <div class="table-title">特色专业</div>
                <el-table
                  empty-text="暂无数据"
                  class="syltable"
                  :data="reseInfo"
                  style="width: 100%"
                  :header-cell-style="{
                    backgroundColor: '#f5f5f5',
                    height: '64px',
                    color: '#333',
                    'font-weight': '500',
                    'text-align': 'center',
                  }"
                  :cell-style="{ height: '48px' }"
                  border
                >
                  <el-table-column label="专业层次" width="150" align="center">
                    <template #default="scope">
                      {{ scope.row.leve }}
                    </template>
                  </el-table-column>
                  <el-table-column label="数量" width="100">
                    <template #default="scope">
                      {{ scope.row.major.length }}
                    </template>
                  </el-table-column>
                  <el-table-column label="专业" prop="`major`">
                    <template #default="scope">
                      <div
                        @click="handleFeatureMajor(item)"
                        v-for="item in scope.row.major"
                        :key="item.code"
                        class="curr item"
                      >
                        <div
                          style="margin: 20px 20px 20rpx 0"
                          v-if="scope.row.major.length"
                        >
                          {{ item.name || '-' }}&nbsp;&nbsp;&nbsp;
                        </div>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>

              <!-- 双一流学科 -->
              <div>
                <div class="table-title">双一流学科</div>
                <el-select
                  :popper-options="{
                    modifiers: [
                      { name: 'computeStyles', options: { adaptive: false } },
                    ],
                  }"
                  class="select-box"
                  v-model="optValue"
                  size="small"
                  style="width: 80px"
                  @change="handleChange"
                >
                  <el-option
                    v-for="item in options"
                    :key="item"
                    :label="item"
                    :value="item"
                  />
                </el-select>
                <el-table
                  empty-text="暂无数据"
                  :data="shaungyiliuInfo"
                  style="width: 100%"
                  :header-cell-style="{
                    backgroundColor: '#f5f5f5',
                    height: '64px',
                    color: '#333',
                    'font-weight': '500',
                    'text-align': 'center',
                  }"
                  :cell-style="{ height: '48px' }"
                  border
                  :span-method="spanMethod"
                >
                  <el-table-column label="数量" width="150" align="center">
                    <template #default="scope">
                      <div style="margin: 0 20px">
                        {{ shaungyiliuInfo.length }}
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column label="学科">
                    <template #default="scope">
                      <div v-for="item in shaungyiliuInfo" :key="item">
                        <div style="margin: 0 20px">{{ item.name }}</div>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>

            <!-- 学科评估 -->
            <div>
              <div class="table-title">学科评估</div>
              <el-select
                :popper-options="{
                  modifiers: [
                    { name: 'computeStyles', options: { adaptive: false } },
                  ],
                }"
                class="select-box"
                v-model="selectZYPJtextVal"
                size="small"
                style="width: 80px"
                @change="zypjHandleChange"
              >
                <el-option
                  v-for="item in selectZYPJtext"
                  :key="item.extTypeId"
                  :label="item.extTypeName"
                  :value="item.extTypeId"
                />
              </el-select>
              <el-table
                empty-text="暂无数据"
                class="syltable"
                :data="pinginfo"
                style="width: 100%"
                :header-cell-style="{
                  backgroundColor: '#f5f5f5',
                  height: '64px',
                  color: '#333',
                  'font-weight': '500',
                  'text-align': 'center',
                }"
                :cell-style="{ height: '48px' }"
                border
                :span-method="spanMethod"
              >
                <el-table-column label="数量" width="150" align="center">
                  <template #default="scope">
                    {{ pinginfo.length }}
                  </template>
                </el-table-column>
                <el-table-column label="专业评级">
                  <template #default="scope">
                    <div v-for="item in pinginfo" :key="item">
                      <div style="margin: 20px 20px 20rpx 0">
                        {{ item.name }} {{ item.level }}&nbsp;&nbsp;&nbsp;
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <!-- 院系设置 -->
            <div>
              <div class="table-title">院系设置</div>

              <el-table
                empty-text="暂无数据"
                class="syltable"
                :data="yxmajor"
                style="width: 100%"
                :header-cell-style="{
                  backgroundColor: '#f5f5f5',
                  height: '64px',
                  color: '#333',
                  'font-weight': '500',
                  'text-align': 'center',
                }"
                :cell-style="{ height: '48px' }"
                border
              >
                <el-table-column label="学院" width="250" align="center">
                  <template #default="scope">
                    {{ scope.row.name }}
                  </template>
                </el-table-column>
                <el-table-column label="所含专业" prop="major">
                  <template #default="scope">
                    <div
                      class="curr item"
                      v-for="item in scope.row.majors"
                      :key="item.code"
                      @click="handleMajorDet(item)"
                    >
                      <div style="margin: 20px 20px 20rpx 0">
                        <span style="padding-bottom: 40rpx"
                          >{{ item.name || '-' }}({{
                            item.level == 'ben' ? '本' : '专'
                          }})&nbsp;&nbsp;</span
                        >
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>

            <!-- 就业报告 -->
            <div>
              <div class="table-title">就业报告</div>
              <div
                v-for="item in jyReport"
                :key="item.webSite"
                style="
                  border-bottom: 1px solid #f2f2f2;
                  line-height: 50px;
                  font-size: 14px;
                "
              >
                <div class="curr" @click="handleReport(item)">
                  <div class="zsjzItem">{{ item.title }}</div>
                  <!-- <div style="flex: 1; text-align: center">浏览{{ item.hits }}</div> -->
                  <!-- <div>
              {{ item.createdAt.match(/^\d{4}-\d{2}-\d{2}/)[0] }}
            </div> -->
                </div>
              </div>
            </div>
          </div>

          <!-- 院校全部简介 -->
          <div v-if="isDecAllShow">
            <div>院校简介</div>
            <div>{{ headerData.introduction }}</div>
            <div class="allBtn curr" @click="handleHidDec">收起</div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="招生简章" name="second">
          <div v-if="!isDetShow">
            <EnrollmentGuide
              :schoolZSData="schoolZSData"
              :total="total"
              @handleDetShow="handleDetShow"
              @handleSearchZsjz="handleSearchZsjz"
            />
            <div style="text-align: center" class="f14">
              <p v-if="dataLoading">加载中...</p>
              <p v-if="noMore">以上为全部</p>
            </div>
          </div>

          <div v-if="isDetShow">
            <enrollment-guide-det
              :zsDetailData="zsDetailData"
              v-loading="enrloomentLoading"
            />
          </div>
        </el-tab-pane>
        <el-tab-pane label="录取分数线" name="third">
          <score-line
            :yearlineData="yearlineData"
            :linePopArrDX5="linePopArrDX5"
            :lineSelecttextDX5="lineSelecttextDX5"
            :planList="planList"
            :filterData="filterData"
            :popArrDXData="popArrDXData"
            @handleUpdateAllList="handleUpdateAllList"
            @handleUpdateMajorLineYear="handleUpdateMajorLineYear"
            @handleUpdateMajorLineProvince="handleUpdateMajorLineProvince"
            @handleUpdateMajorLineSubject="handleUpdateMajorLineSubject"
            @handleUpdateMajorLineLevel="handleUpdateMajorLineLevel"
          />
        </el-tab-pane>
        <el-tab-pane label="招生计划" name="1">
          <!-- 招生计划 -->
          <student-plan
            :studentPlanSelectedData="studentPlanSelectedData"
            :studentPlanData="studentPlanData"
            :planPopArrDXData="planPopArrDXData"
            @updatePlanProvince="updatePlanProvince"
            @updatePlanYear="updatePlanYear"
            @updatePlanSubject="updatePlanSubject"
            @updatePlanLevel="updatePlanLevel"
          />
        </el-tab-pane>
        <el-tab-pane label="提前批招生计划" name="2">
          <pre-plan
            :prePlanSelectData="prePlanSelectData"
            :prePlanList="prePlanList"
            :prePreData="prePreData"
            @updatePrePlanProvince="updatePrePlanProvince"
            @updatePrePlanYear="updatePrePlanYear"
          />
        </el-tab-pane>
        <el-tab-pane label="提前批分数线" name="fourth">
          <pre-line
            :preLineSelectData="preLineSelectData"
            :preLineList="preLineList"
            :preLineData="preLineData"
            @updatePreLineProvince="updatePreLineProvince"
            @updatePreLine="updatePreLine"
          />
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup>
import { nextTick, ref, watch } from 'vue';
import imageUrl1 from '@/assets/images/jiben-1-.png';
import imageUrl2 from '@/assets/images/jiben-2-.png';
import imageUrl3 from '@/assets/images/jiben-3-.png';

import imageUrl4 from '@/assets/images/jiben-4-.png';

import imageUrl5 from '@/assets/images/jiben-5-.png';

import imageUrl6 from '@/assets/images/jiben-6-.png';

import imageUrl7 from '@/assets/images/jiben-7-.png';
import imageUrl8 from '@/assets/images/jiben-8-.png';
import EnrollmentGuide from '@/components/EnrollmentGuide';
import EnrollmentGuideDet from '@/components/EnrollmentGuideDet';
import ScoreLine from '@/components/ScoreLine';
import StudentPlan from '@/components/StudentPlan';
import PrePlan from '@/components/PrePlan';
import PreLine from '@/components/PreLine';

import {
  getSchoolHome,
  getSchoolSubjectEvaluate,
  getSchoolYXMajor,
  getSchoolJY,
  getSchoolZS,
  getSchoolYearline,
  getSchoolScoreline,
  getSchoolScorelineFilter,
  getSchoolPlan,
  getPreBatchPlan,
  getPreBatchSearch,
  getLikeSave,
  getLikeList,
  schoolScorelineFilter,
  getSchoolZSDetail,
  getSchoolPlanFilter,
} from '@/api/appv2/appv2';
import { ElMessage } from 'element-plus';
const studentId = localStorage.getItem('student_id');
const disabled = computed(() => dataLoading.value || noMore.value);
const noMore = computed(() => noMoreData.value.length <= 0);
const noMoreData = ref([]);
const selecttextDX2 = ref('');
const popArrDX2 = ref('');
const dataLoading = ref(false);
const enrloomentLoading = ref(false);
const activeName = ref('first');
const isDecAllShow = ref(false);
const selectZYPJtext = ref([]);
const isDetShow = ref(false);
const filterData = ref({
  popArrDX6: [],
  selecttextDX6: '',
});
const zsDetailData = ref({});
// const popArrDX6 = ref([]);
// const selecttextDX6 = ref("")
const selectZYPJtextVal = ref('');
const options = ref([]);
const shaungyiliuInfo = ref([]);
const optValue = ref('');
const pinginfo = ref([]);
const isSelected = ref(false);
const props = defineProps({
  baseData: {
    type: Object,
    default: () => {},
  },
});
const student_Province = ref(localStorage.getItem('student_Province'));
const requestData = ref({
  // pid: localStorage.getItem("student_Province"),
  pid: '',
  collegeCode: props.baseData?.collegeCode || props.baseData?.code,
});
const total = ref(0);
const reseInfo = ref([
  { leve: '国家', major: [] },
  { leve: '省级', major: [] },
]);
const jibenInfo = ref({});
const zsjzData = ref({
  page: 1,
  pageSize: 20,
  code: props.baseData?.collegeCode || props.baseData?.code,
});
const jbIconModul = ref({
  办学类型: imageUrl1,
  地址: imageUrl2,
  隶属: imageUrl3,
  高校层次: imageUrl4,
  建校时间: imageUrl5,
  硕士点: imageUrl6,
  博士点: imageUrl7,
  国家重点学科: imageUrl8,
});
const headerData = ref({});
watch(
  () => props.baseData,
  (newVal) => {
    if (newVal) {
      schoolZSData.value = [];
      zsjzData.value.page = 1;
      fetchSchoolScoreline();
      fetchSchoolYearline();
      fetchSchoolZS();
      fetchSchoolJY();
      fetchSchoolHome();
      fetchSchoolSubjectEvaluate();
      fetchSchoolYXMajor();
    }
  }
);
const linePopArrDX5 = ref([]);
const lineSelecttextDX5 = ref([]);
const yearlineData = ref([]);
const spanMethod = ({ row, column, rowIndex, columnIndex }) => {
  // if(rowIndex==)
  if (rowIndex != 0) {
    return {
      rowspan: 0,
      colspan: 0,
    };
  }
};

// 录取分数线--专业分数线or院校分数线筛选条件接口
const fetchSchoolScorelineFilter = () => {
  getSchoolScorelineFilter().then((res) => {
    let idStoreData = false;
    let storeData = [];
    if (res.code == 20000) {
      // 院校分数线默认第一个省份数据
      filterData.value.popArrDX6 = res.data;

      if (localStorage.getItem('provinceId')) {
        idStoreData = filterData.value.popArrDX6.some(
          (obj) => obj.provinceCode == localStorage.getItem('provinceId')
        );
        if (idStoreData) {
          storeData = filterData.value.popArrDX6.filter(
            (obj) => obj.provinceCode == localStorage.getItem('provinceId')
          );
        }
      }
      if (localStorage.getItem('provinceId') && idStoreData) {
        filterData.value.selecttextDX6 = storeData[0].provinceCode;
        popArrDXData.value.popArrDX6 = storeData[0].years.map((v) => v.year);
        popArrDXData.value.selecttextDX6 = popArrDXData.value.popArrDX6[0];
        popArrDXData.value.selecttextDX7 = storeData[0].years[0].course[0];
        popArrDXData.value.selecttextDX8 = storeData[0].years[0].batch[0];
        popArrDXData.value.popArrDX7 = storeData[0].years[0].course;
        popArrDXData.value.popArrDX8 = storeData[0].years[0].batch;
      } else {
        filterData.value.selecttextDX6 = res.data[0].provinceCode;
        popArrDXData.value.popArrDX6 = res.data[0].years.map((v) => v.year);
        popArrDXData.value.selecttextDX6 = popArrDXData.value.popArrDX6[0];
        popArrDXData.value.selecttextDX7 = res.data[0].years[0].course[0];
        popArrDXData.value.selecttextDX8 = res.data[0].years[0].batch[0];
        popArrDXData.value.popArrDX7 = res.data[0].years[0].course;
        popArrDXData.value.popArrDX8 = res.data[0].years[0].batch;
      }

      fetchSchoolYearline();
      fetchSchoolScoreline();
    }
  });
};
fetchSchoolScorelineFilter();

// 院校分数线列表接口
const fetchSchoolYearline = () => {
  requestData.value.pid = filterData.value.selecttextDX6;
  getSchoolYearline(requestData.value).then((res) => {
    if (res.code == 20000) {
      yearlineData.value = res.data;
      linePopArrDX5.value = [];
      lineSelecttextDX5.value = [];
      if (res.data.length > 1) {
        res.data?.forEach((item) => {
          let arr = [];
          item.courses.forEach((item2) => {
            arr.push(item2.name);
          });
          linePopArrDX5.value.push(arr);
          lineSelecttextDX5.value.push(arr[0]);
        });
      } else {
        let arr = [];
        res.data[0].courses.forEach((item2) => {
          arr.push(item2.name);
        });
        linePopArrDX5.value.push(arr);
        lineSelecttextDX5.value.push(arr[0]);
      }
    }
  });
};

const handleMajorDet = () => {};
const liskeSaveData = ref({
  type: 'school',
  targetid: '',
  operate: '',
});

const handleDetShow = (item) => {
  nextTick(() => {
    isDetShow.value = true;
    fetchSchoolZSDetail(item);
  });
};

const fetchSchoolZSDetail = (item) => {
  enrloomentLoading.value = true;
  getSchoolZSDetail({ id: item.id })
    .then((res) => {
      if (res.code == 20000) {
        zsDetailData.value = res.data;
        enrloomentLoading.value = false;
      } else {
        enrloomentLoading.value = false;
      }
    })
    .catch(() => {
      enrloomentLoading.value = false;
    });
};

const updatePlanData = (val, resFilter, resut) => {
  // 更新招生计划数据
  planPopArrDXData.value.popArrDX6 = resut[0].years.map((v) => v.year);
  prePreData.value.prePlanPopArrDX6 = [...planPopArrDXData.value.popArrDX6];
  preLineData.value.preLinepopArrDX6 = [...planPopArrDXData.value.popArrDX6];

  planPopArrDXData.value.selecttextDX6 = resut[0].years[0].year;
  preLineData.value.preLineselecttextDX6 = prePreData.value.prePlanPopArrDX6[0];
  prePreData.value.prePlanSelecttextDX6 = prePreData.value.prePlanPopArrDX6[0];

  studentPlanSelectedData.value.selecttextDX6 = val;
  planPopArrDXData.value.popArrDX7 = resFilter[0].course;
  planPopArrDXData.value.selecttextDX7 = planPopArrDXData.value.popArrDX7[0];
  planPopArrDXData.value.popArrDX8 = resFilter[0].batch;
  planPopArrDXData.value.selecttextDX8 = planPopArrDXData.value.popArrDX8[0];

  fetchSchoolPlan();
};

const updatePreBatchData = (val) => {
  prePlanSelectData.value.selecttextDX6 = val;
  fetchPreBatchPlan();

  preLineSelectData.value.selecttextDX6 = val;
  fetchPreBatchSearch();
};

const updateScoreAndYearData = (resFilter) => {
  popArrDXData.value.popArrDX6 = resFilter
    .map((item) => item.year)
    .filter((v) => v > 2020);
  popArrDXData.value.selecttextDX6 = popArrDXData.value.popArrDX6[0];
  popArrDXData.value.popArrDX7 = resFilter[0].course;
  popArrDXData.value.selecttextDX7 = popArrDXData.value.popArrDX7[0];
  popArrDXData.value.popArrDX8 = resFilter[0].batch;
  popArrDXData.value.selecttextDX8 = popArrDXData.value.popArrDX8[0];

  fetchSchoolScoreline();
  fetchSchoolYearline();
};

const handleUpdateAllList = (val) => {
  localStorage.setItem('provinceId', val);
  filterData.value.selecttextDX6 = val;

  let resFilter = filterData.value.popArrDX6.find(
    (v) => v.provinceCode == val
  ).years;
  let resut = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  );

  updatePlanData(val, resFilter, resut);
  updatePreBatchData(val);
  updateScoreAndYearData(resFilter);
};

const handleUpdateMajorLineProvince = (val) => {
  localStorage.setItem('provinceId', val);

  let resFilter = filterData.value.popArrDX6.find(
    (v) => v.provinceCode == val
  ).years;
  let resut = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  );

  updatePlanData(val, resFilter, resut);
  updatePreBatchData(val);
  updateScoreAndYearData(resFilter);
};

const updateLocalStorageAndFilterData = (val) => {
  localStorage.setItem('provinceId', val);
  filterData.value.selecttextDX6 = val;
  return filterData.value.popArrDX6.filter((v) => v.provinceCode === val)[0]
    .years;
};

const updatePrePlanProvince = (val) => {
  let resFilter = updateLocalStorageAndFilterData(val);

  prePreData.value.prePlanPopArrDX6 = [];
  preLineData.value.preLinepopArrDX6 = [];
  planPopArrDXData.value.popArrDX6 = [];

  let resut = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  );
  resut[0].years.forEach((v) => {
    prePreData.value.prePlanPopArrDX6.push(v.year);
    preLineData.value.preLinepopArrDX6.push(v.year);
    planPopArrDXData.value.popArrDX6.push(v.year);
  });

  prePreData.value.prePlanSelecttextDX6 = prePreData.value.prePlanPopArrDX6[0];
  preLineData.value.preLineselecttextDX6 = prePreData.value.prePlanPopArrDX6[0];
  planPopArrDXData.value.selecttextDX6 = prePreData.value.prePlanPopArrDX6[0];

  fetchPreBatchPlan();
  fetchSchoolYearline();
  fetchSchoolScoreline();
  fetchSchoolPlan();
};

const updatePreLineProvince = (val) => {
  let resFilter = updateLocalStorageAndFilterData(val);

  prePreData.value.prePlanPopArrDX6 = [];
  preLineData.value.preLinepopArrDX6 = [];
  planPopArrDXData.value.popArrDX6 = [];

  let resut = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  );
  resut[0].years.forEach((v) => {
    prePreData.value.prePlanPopArrDX6.push(v.year);
    preLineData.value.preLinepopArrDX6.push(v.year);
    planPopArrDXData.value.popArrDX6.push(v.year);
  });

  preLineData.value.preLineselecttextDX6 =
    preLineData.value.preLinepopArrDX6[0];
  prePreData.value.prePlanSelecttextDX6 = preLineData.value.preLinepopArrDX6[0];
  planPopArrDXData.value.selecttextDX6 = preLineData.value.preLinepopArrDX6[0];

  studentPlanSelectedData.value.selecttextDX6 = val;
  prePlanSelectData.value.selecttextDX6 = val;
  preLineSelectData.value.preLineselecttextDX6 = val;

  fetchPreBatchSearch();
  fetchSchoolYearline();
  fetchSchoolScoreline();
  fetchSchoolPlan();
  fetchPreBatchPlan();
};

const handleMyLike = () => {
  isSelected.value = !isSelected.value;
  liskeSaveData.value.targetid =
    props.baseData?.collegeCode || props.baseData?.code;
  liskeSaveData.value.studentId = localStorage.getItem('student_id');
  isSelected.value
    ? (liskeSaveData.value.operate = 'save')
    : (liskeSaveData.value.operate = 'del');
  getLikeSave(liskeSaveData.value).then((res) => {
    if (res.code == 20000) {
      ElMessage({
        message: res.msg,
        type: 'success',
      });
    }
  });
};

const fetchLikeList = () => {
  let reqData = {
    // detail: "1",
    type: 'school',
    studentId: localStorage.getItem('student_id'),
  };
  getLikeList(reqData).then((res) => {
    let likeSchoolArr = res.data.school.split(',');
    let index = likeSchoolArr.indexOf(
      props.baseData?.collegeCode || props.baseData?.code
    );
    index == -1 ? (isSelected.value = false) : (isSelected.value = true);
  });
};
if (localStorage.getItem('student_id')) {
  fetchLikeList();
}
const preLineData = ref({
  preLineselecttextDX6: '',
  preLinepopArrDX6: '',
});

const updatePreLine = (val) => {
  preLineData.value.preLineselecttextDX6 = val;
  fetchPreBatchSearch();
};
const preLineList = ref([]);
const fetchPreBatchSearch = () => {
  let reqData = {
    year: preLineData.value.preLineselecttextDX6,
    collegeCode: props.baseData?.collegeCode || props.baseData?.code,
    provinceCode: preLineSelectData.value.selecttextDX6,
  };
  getPreBatchSearch(reqData)
    .then((res) => {
      if (res.code == 20000) {
        preLineList.value = res.data;
      }
    })
    .catch(() => {});
};
const prePreData = ref({
  prePlanSelecttextDX6: '',
  prePlanPopArrDX6: [],
});

const prePlanList = ref([]);
const fetchPreBatchPlan = () => {
  let reqData = {
    year: prePreData.value.prePlanSelecttextDX6,
    collegeCode: props.baseData?.collegeCode || props.baseData?.code,
    provinceCode: prePlanSelectData.value.selecttextDX6,
  };
  getPreBatchPlan(reqData)
    .then((res) => {
      if (res.code == 20000) {
        prePlanList.value = res.data;
      }
    })
    .catch(() => {});
};
const handleUpdateMajorLineSubject = (val) => {
  popArrDXData.value.selecttextDX7 = val;
  fetchSchoolScoreline();
};

const updatePrePlanYear = (val) => {
  prePreData.value.prePlanSelecttextDX6 = val;
  fetchPreBatchPlan();
};
const handleUpdateMajorLineLevel = (val) => {
  popArrDXData.selecttextDX8 = val;
  fetchSchoolScoreline();
};
const updatePlanLevel = (val) => {
  planPopArrDXData.value.selecttextDX8 = val;
  fetchSchoolPlan();
};
const updatePlanSubject = (val) => {
  planPopArrDXData.value.selecttextDX7 = val;
  fetchSchoolPlan();
};

// 招生计划省份筛选
const updatePlanProvince = (val) => {
  localStorage.setItem('provinceId', val);
  let resFilter = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  )[0].years;

  let resultFilter = filterData.value.popArrDX6.filter(
    (v) => v.provinceCode == val
  )[0].years;

  planPopArrDXData.value.popArrDX6 = [];

  let result = prePlanSelectData.value.popArrDX6.filter(
    (v) => v.provinceCode == studentPlanSelectedData.value.selecttextDX6
  );
  result[0].years.forEach((v) => {
    planPopArrDXData.value.popArrDX6.push(v.year);
  });
  planPopArrDXData.value.selecttextDX6 = planPopArrDXData.value.popArrDX6[0];

  let resultData = resFilter.filter(
    (v) => v.year == planPopArrDXData.value.selecttextDX6
  );
  // 院校分数线
  filterData.value.selecttextDX6 = val;
  // popArrDXData.value.popArrDX6 = resFilter
  //   .map((item) => item.year)
  //   .filter((v) => v > 2020);

  popArrDXData.value.popArrDX6 = resultFilter
    .map((item) => item.year)
    .filter((v) => v > 2020);

  popArrDXData.value.selecttextDX6 = popArrDXData.value.popArrDX6[0];
  popArrDXData.value.popArrDX7 = resultFilter[0].course;
  popArrDXData.value.selecttextDX7 = popArrDXData.value.popArrDX7[0];
  popArrDXData.value.popArrDX8 = resultFilter[0].batch;
  popArrDXData.value.selecttextDX8 = popArrDXData.value.popArrDX8[0];
  // 现根据年份请求数据
  fetchSchoolYearline();
  fetchSchoolScoreline();

  // 提前批招生计划
  prePlanSelectData.value.selecttextDX6 = val;
  fetchPreBatchPlan();
  // 提前批分数线
  preLineSelectData.value.selecttextDX6 = val;
  fetchPreBatchSearch();

  // planPopArrDXData.value.selecttextDX6 = resultData[0].year;
  planPopArrDXData.value.popArrDX7 = resultData[0].course;
  planPopArrDXData.value.selecttextDX7 = resultData[0].course[0];
  planPopArrDXData.value.popArrDX8 = resultData[0].batch;
  planPopArrDXData.value.selecttextDX8 = resultData[0].batch[0];
  fetchSchoolPlan();
};

const updatePlanYear = (val) => {
  planPopArrDXData.value.selecttextDX6 = val;
  fetchSchoolPlan();
};

const handleUpdateMajorLineYear = (province, val) => {
  let resFilter = filterData.value.popArrDX6
    .filter((v) => v.provinceCode == province)[0]
    .years.filter((v) => v.year == val);
  popArrDXData.value.popArrDX7 = resFilter[0].course;
  popArrDXData.value.selecttextDX7 = popArrDXData.value.popArrDX7[0];
  popArrDXData.value.popArrDX8 = resFilter[0].batch;
  popArrDXData.value.selecttextDX8 = popArrDXData.value.popArrDX8[0];
  fetchSchoolScoreline();
};
const handleSearchZsjz = (val) => {
  schoolZSData.value = [];
  zsjzData.value.keywords = val;
  fetchSchoolZS();
};
const load = () => {
  if (activeName.value == 'second') {
    if (noMoreData.value.length <= 0) {
      return;
    } else {
      zsjzData.value.page += 1;
      fetchSchoolZS();
    }
  }
};
const handleReport = (item) => {
  window.open(item.webSite);
};
const handleClick = (tab, event) => {
  isDetShow.value = false;
};
const handleLookAll = () => {
  isDecAllShow.value = true;
};
const handleHidDec = () => {
  isDecAllShow.value = false;
};
const rankingInfo = ref({});

const handleChange = (val) => {
  headerData.value.sylMajor.sylSubjectsGroup.forEach((item) => {
    if (item.evaluations == val) {
      shaungyiliuInfo.value = item.subjects;
    }
  });
};
const zypjHandleChange = (val) => {
  fetchSchoolSubjectEvaluate(val);
};
// 获取专业选科筛选条件
const popArrDXData = ref({
  popArrDX6: [],
  popArrDX7: [],
  popArrDX8: [],
  selecttextDX6: '',
  selecttextDX7: '',
  selecttextDX8: '',
});
const planPopArrDXData = ref({
  popArrDX6: [],
  popArrDX7: [],
  popArrDX8: [],
  selecttextDX6: '',
  selecttextDX7: '',
  selecttextDX8: '',
});
const studentPlanData = ref([]);
const fetchSchoolPlan = () => {
  let reqData = {
    pid: studentPlanSelectedData.value.selecttextDX6,
    collegeCode: props.baseData?.collegeCode || props.baseData?.code,
    year: planPopArrDXData.value.selecttextDX6,
    course: planPopArrDXData.value.selecttextDX7,
    batch: planPopArrDXData.value.selecttextDX8,
  };
  // majorLineLoading.value = true;
  getSchoolPlan(reqData)
    .then((res) => {
      if (res.code == 20000) {
        studentPlanData.value = res.data;
      }
    })
    .catch(() => {});
};
const studentPlanSelectedData = ref({
  popArrDX6: [],
  selecttextDX6: '',
});

// 提前批招生计划省份选择数据
const prePlanSelectData = ref({
  popArrDX6: [],
  selecttextDX6: '',
});

// 提前批分数线省份选择数据
const preLineSelectData = ref({
  popArrDX6: [],
  selecttextDX6: '',
});

// 提前批筛选数据
const fetchSchoolPlanFilter = () => {
  getSchoolPlanFilter().then((res) => {
    // 提前批招生计划
    prePlanSelectData.value.popArrDX6 = [];
    prePlanSelectData.value.popArrDX6 = res.data;

    if (
      Number(localStorage.getItem('provinceId')) &&
      prePlanSelectData.value.popArrDX6.some(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )
    ) {
      prePlanSelectData.value.selecttextDX6 = Number(
        localStorage.getItem('provinceId')
      );
    } else {
      prePlanSelectData.value.selecttextDX6 =
        prePlanSelectData.value.popArrDX6[0].provinceCode || '';
    }

    let result = res.data.filter(
      (v) => v.provinceCode == prePlanSelectData.value.selecttextDX6
    );

    prePreData.value.prePlanPopArrDX6 = result[0].years.map((v) => v.year);
    prePreData.value.prePlanSelecttextDX6 =
      prePreData.value.prePlanPopArrDX6[0];

    // 招生计划
    studentPlanSelectedData.value.popArrDX6 = [];
    studentPlanSelectedData.value.popArrDX6 = res.data;

    if (
      Number(localStorage.getItem('provinceId')) &&
      res.data.some(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )
    ) {
      studentPlanSelectedData.value.selecttextDX6 = Number(
        localStorage.getItem('provinceId')
      );
    } else {
      studentPlanSelectedData.value.selecttextDX6 =
        studentPlanSelectedData.value.popArrDX6[0].provinceCode || '';
    }
    if (
      localStorage.getItem('provinceId') &&
      studentPlanSelectedData.value.popArrDX6.some(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )
    ) {
      planPopArrDXData.value.popArrDX6 = res.data
        .filter(
          (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
        )[0]
        .years.map((v) => v.year);
      planPopArrDXData.value.popArrDX7 = res.data.filter(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )[0].years[0].course;
      planPopArrDXData.value.popArrDX8 = res.data.filter(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )[0].years[0].batch;
    } else {
      planPopArrDXData.value.popArrDX6 = res.data[0].years.map((v) => v.year);
      planPopArrDXData.value.popArrDX7 = res.data[0].years[0].course;
      planPopArrDXData.value.popArrDX8 = res.data[0].years[0].batch;
    }
    planPopArrDXData.value.selecttextDX6 = planPopArrDXData.value.popArrDX6[0];
    planPopArrDXData.value.selecttextDX7 = planPopArrDXData.value.popArrDX7[0];
    planPopArrDXData.value.selecttextDX8 = planPopArrDXData.value.popArrDX8[0];

    // 提前批分数线筛选数据
    preLineSelectData.value.popArrDX6 = res.data;
    if (
      Number(localStorage.getItem('provinceId')) &&
      preLineSelectData.value.popArrDX6.some(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )
    ) {
      preLineSelectData.value.selecttextDX6 = Number(
        localStorage.getItem('provinceId')
      );
    } else {
      preLineSelectData.value.selecttextDX6 =
        preLineSelectData.value.popArrDX6[0].provinceCode;
    }

    if (
      Number(localStorage.getItem('provinceId')) &&
      res.data.some(
        (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
      )
    ) {
      preLineData.value.preLinepopArrDX6 = res.data
        .filter(
          (v) => v.provinceCode == Number(localStorage.getItem('provinceId'))
        )[0]
        .years.map((v) => v.year);
    } else {
      preLineData.value.preLinepopArrDX6 = res.data[0].years.map((v) => v.year);
    }

    preLineData.value.preLineselecttextDX6 =
      preLineData.value.preLinepopArrDX6[0];
    fetchSchoolPlan();
    fetchPreBatchPlan();
    fetchPreBatchSearch();
  });
};
fetchSchoolPlanFilter();

const fetchSchoolHome = () => {
  getSchoolHome({
    code: props.baseData?.collegeCode || props.baseData?.code,
  }).then((res) => {
    if (res.code == 20000) {
      headerData.value = res.data;
      reseInfo.value[0].major = res.data.featureMajor.countries;
      reseInfo.value[1].major = res.data.featureMajor.provinces;
      rankingInfo.value['校友会'] = headerData.value.rankingOfXYH;
      rankingInfo.value['软科'] = headerData.value.rankingOfRK;
      rankingInfo.value['QS'] = headerData.value.rankingOfQS;
      rankingInfo.value['USNews'] = headerData.value.rankingOfUSNews;
      optValue.value = res.data.sylMajor.sylEvalutions[0];
      options.value = res.data.sylMajor.sylEvalutions || [];
      shaungyiliuInfo.value =
        (res.data.sylMajor.sylSubjectsGroup[0] || {}).subjects || [];
      // collegeData.value.categor = res.data.categories[0];
      let natureType = '';
      if (headerData.value.natureType == 'public') {
        natureType = '公办';
      } else if (headerData.value.natureType == 'private') {
        natureType = '民办';
      } else {
        natureType = '中外/港澳';
      }
      jibenInfo.value['办学类型'] = natureType;
      jibenInfo.value['地址'] =
        headerData.value.provinceName + '-' + headerData.value.cityName;
      jibenInfo.value['隶属'] =
        headerData.value.belong.length > 0 ? headerData.value.belong : '-';

      jibenInfo.value['高校层次'] =
        headerData.value.eduLevel == 'ben' ? '本科' : '专科';
      let pointsOfShuo = 0;
      headerData.value.pointsOfShuo.forEach((item) => {
        pointsOfShuo += item.number;
      });
      jibenInfo.value['建校时间'] = headerData.value.createdYear || '-';
      let pointsOfBo = 0;
      headerData.value.pointsOfBo.forEach((items) => {
        pointsOfBo += items.number;
      });
      jibenInfo.value['国家重点学科'] =
        headerData.value.featureMajor.countries.length || '-';
      jibenInfo.value['硕士点'] = pointsOfShuo || '-';
      jibenInfo.value['博士点'] = pointsOfBo || '-';
    }
  });
};
const planList = ref([]);
// 专业分数线
const fetchSchoolScoreline = () => {
  let reqData = {
    pid: filterData.value.selecttextDX6,
    collegeCode: props.baseData?.collegeCode || props.baseData?.code,
    year: popArrDXData.value.selecttextDX6,
    course: popArrDXData.value.selecttextDX7,
    batch: popArrDXData.value.selecttextDX8,
  };
  getSchoolScoreline(reqData)
    .then((res) => {
      if (res.code == 20000) {
        planList.value = res.data;
      }
    })
    .catch(() => {});
};

const fetchSchoolSubjectEvaluate = (extTypeId = '4') => {
  let requestData = {
    code: props.baseData?.collegeCode || props.baseData?.code,
    extTypeId,
  };
  getSchoolSubjectEvaluate(requestData).then((res) => {
    if (res.code == 20000) {
      selectZYPJtext.value = res.data.filter;
      pinginfo.value = res.data.data?.subjectEvaluates;
      // selectZYPJtextVal.value = res.data.data.filter
      selectZYPJtextVal.value = selectZYPJtext.value.filter(
        (v) => v.extTypeId == extTypeId
      )[0].extTypeId;
    }
  });
};
const yxmajor = ref([]);
const fetchSchoolYXMajor = () => {
  let requestData = {
    code: props.baseData?.collegeCode || props.baseData?.code,
  };
  getSchoolYXMajor(requestData).then((res) => {
    yxmajor.value = res.data;
  });
};
const jyReport = ref([]);
const fetchSchoolJY = () => {
  let requestData = {
    page: 1,
    pageSize: 5,
    code: props.baseData?.collegeCode || props.baseData?.code,
  };

  getSchoolJY(requestData).then((res) => {
    if (res.code == 20000) {
      jyReport.value = res.data;
    }
  });
};

const schoolZSData = ref([]);
const fetchSchoolZS = () => {
  dataLoading.value = true;
  getSchoolZS(zsjzData.value)
    .then((res) => {
      if (res.code == 20000) {
        dataLoading.value = false;
        total.value = res.total;
        noMoreData.value = res.data;
        // schoolZSData.value = res.data;
        schoolZSData.value = [...schoolZSData.value, ...res.data];
        schoolZSData.value.forEach((item) => {
          item.updatedAt = item.updatedAt.substring(
            0,
            item.updatedAt.indexOf('T')
          );
        });
      } else {
        dataLoading.value = false;
      }
    })
    .catch((e) => {
      dataLoading.value = false;
    });
};
zsjzData.value.page = 1;
fetchSchoolZS();
fetchSchoolJY();
fetchSchoolYXMajor();
fetchSchoolSubjectEvaluate();
fetchSchoolHome();
// fetchSchoolYearline()
// fetchSchoolPlan()
// fetchSchoolScoreline();

const handleTabActiveName = () => {
  activeName.value = 'fourth';
};
defineExpose({
  handleTabActiveName,
});
</script>

<style lang="scss" scoped>
.zsjzItem:hover {
  color: #409eff;
}

.select-box {
  margin-bottom: 20px;
}

.table-title {
  color: #1d2129;
  font-weight: 400;
  font-size: 16px;
  margin: 10px 0;
}

.syltable {
  ::v-deep(.cell) {
    display: flex;
    flex-wrap: wrap;
  }
}

#InformationBase {
  .imgs {
    width: 70px;
  }

  .tags {
    margin: 5px 0;
  }

  .colldec {
    font-size: 12px;
    color: #86909c;
  }

  .tabs {
    margin-top: 20px;
  }

  .introduction {
    margin-top: 20px;
    font-size: 14px;
    color: #86909c;
  }

  .allBtn {
    color: #165dff;
    margin-left: 5px;
  }

  .ranking-item {
    width: 70px;
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    // margin-right: 10px;
    border-radius: 10px;
    background-color: #ffe2da;

    .text-ranking-value {
      color: #ff3b0a;
      font-size: 20px;
      font-weight: bold;
    }

    .text-ranking-title {
      color: #464646;
      font-size: 12px;
    }
  }
}

::v-deep(.el-input-group__append) {
  width: 70px;
  background: #409eff;
  color: #fff;
}

.icon-aixin1 {
  color: #409eff;
}
</style>
<style lang="scss">
#InformationBase {
  .el-tabs__header {
    position: sticky;
    /* top: -20px; */
    top: 0;
    left: 0;
    z-index: 999;
    background: #fff;
  }
}
</style>
